import unittest

import app
from api.login import LoginAPI

from api.test01_staff import IHRMStaff
from lib.dbutil import DBUtil
from utils import com


class IHRMStaffAPI(unittest.TestCase):
    ID=None
    token=None
    @classmethod
    def setUpClass(cls) -> None:
        cls.login_api=LoginAPI()
        response=cls.login_api.login(app.LOGIN_DATA)
        print(response.json())
        IHRMStaffAPI.token="Bearer "+response.json().get("data")
        print(IHRMStaffAPI.token)
        #清理数据
        DBUtil.exe_sql("delete from bs_user WHERE mobile = '13634267789';")
    @classmethod
    def tearDownClass(cls) -> None:
        DBUtil.exe_sql("delete from bs_user WHERE mobile = '13634267789';")


    def setUp(self) -> None:
        self.ihrm_staff=IHRMStaff()
    def tearDown(self) -> None:
        pass
    def test01_satff(self):
        response=self.ihrm_staff.staff(IHRMStaffAPI.token)
        print(response.json())
        com(self, response, 200, True, 10000, "成功")

    #添加员工
    def test02_insert_staff(self):
        response=self.ihrm_staff.insert_staff({"username":"刘能","mobile":"13634267789","worknum":"0112125500"},IHRMStaffAPI.token)
        print(response.json())
        IHRMStaffAPI.ID=response.json().get("data").get("id")
        com(self, response, 200, True, 10000, "成功")


    #修改员工
    def test03_update_staff(self):
        response=self.ihrm_staff.update_staff({"username":"刘能88899"},IHRMStaffAPI.token,IHRMStaffAPI.ID)
        print(response.json())
        com(self,response,200,True,10000,"成功")
    #查询员工
    def test04_selete_staff(self):
        response=self.ihrm_staff.select_staff(IHRMStaffAPI.token,IHRMStaffAPI.ID)
        print(response.json())
        com(self, response, 200, True, 10000, "成功")
    #删除员工
    def test05_delete_staff(self):
        response=self.ihrm_staff.delete_staff(IHRMStaffAPI.token,IHRMStaffAPI.ID)
        print(response.json())
        com(self, response, 200, True, 10000, "成功")

